const mountElement = require('./mountElement')
const diff = require('./diff')
const patch = require('./patch')
const { setProps } = require('./DOM')

function render(element, node) {//  node :父节点  element : 
  node.appendChild(mountElement(element))
}

function hyperscript(type, props, children) {
  //这里貌似babel 会将dom处理成这样的js对象
  console.log('babel')
  props = props || {}

  // children could be both primitive type like string or number,
  // or an array of element
  return {
    type,
    props,
    children
  }
}

/** 
 * This is actually not `setState` at all,
 * it's just the entry for the diff algorithm.
 * In react, setState is the entry so here we keep the consistency
*/
function setState(parent, prevElement, nextElement) {
  const p = diff(prevElement, nextElement) //比较不同的vdom 
  console.log(p)
  patch(parent, p) //根据传入的p 来处理处理dom
}

module.exports = {
  hyperscript,
  render,
  setState
}
